package cn.wolfcode.wechat.controller;

import cn.wolfcode.wechat.domain.Hire;
import cn.wolfcode.wechat.service.IHireService;
import cn.wolfcode.wechat.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class HireController {

    @Autowired
    private IHireService hireService;

    @RequestMapping("hire")
    public String hirePage(Model model){
        model.addAttribute("data",hireService.selectAll());
        return "hire";
    }
    @RequestMapping("recruitPerson")
    public String recruitPerson(){
        return "add_person";
    }
    @RequestMapping("addHire")
    @ResponseBody
    public JSONResult addHire(Hire hire){
        JSONResult result = new JSONResult();
        try {
            hireService.save(hire);
            result = new JSONResult("保存成功");
        } catch (Exception e) {
            e.printStackTrace();
            result = new JSONResult(false, e.getMessage());
        }
        return result;
    }
}
